package com.cybertron.lockdown.spider.handler;

import us.codecraft.webmagic.Spider;

import java.io.BufferedReader;
import java.io.PrintWriter;

/**
 * Created by xiezhouyan on 15-1-20.
 */
public abstract class Handler implements Runnable {

    protected final BufferedReader in;
    protected final PrintWriter out;
    protected final Spider spider;
    protected final HandleTask task;
    protected final HandleRequest request;
    private boolean isStoped;

    public Handler(BufferedReader in, PrintWriter out, Spider spider, HandleTask task, HandleRequest request) {
        super();
        this.in = in;
        this.out = out;
        this.spider = spider;
        this.task = task;
        this.request = request;
        isStoped = false;
    }

    @Override
    public void run() {
        execute();
    }

    public abstract void execute();

    public void stop() {
        isStoped = true;
    }

    protected boolean isStoped() {
        return isStoped;
    }
}
